//
//  DelTagView.m
//  MeiXiu
//
//  Created by Yuan on 13-2-1.
//
//

#import "DelTagView.h"

@implementation DelTagView
@synthesize btn;
@synthesize titleLbl;


-(void)dealloc
{
//    [titleLbl release];
    titleLbl = nil;
//    [super dealloc];
}


- (NSArray *)getColor
{
    NSArray *color1 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.611],[NSNumber numberWithFloat:0.472],[NSNumber numberWithFloat:0.240], nil];
    NSArray *color2 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.243],[NSNumber numberWithFloat:0.501],[NSNumber numberWithFloat:0.129], nil];
    NSArray *color3 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.177],[NSNumber numberWithFloat:0.395],[NSNumber numberWithFloat:0.501], nil];
    NSArray *color4 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.458],[NSNumber numberWithFloat:0.127],[NSNumber numberWithFloat:0.501], nil];
    NSArray *color5 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.338],[NSNumber numberWithFloat:0.501],[NSNumber numberWithFloat:0.474], nil];
    NSArray *color6 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.131],[NSNumber numberWithFloat:0.501],[NSNumber numberWithFloat:0.351], nil];
    NSArray *colors = [NSArray arrayWithObjects:color1,color2,color3,color4,color5,color6, nil];
       
    srandom(time(NULL)); //将随机数种子重置,
    int idx=rand()%6;
    if (idx>=6||idx<0)idx = 0;
    NSArray *color = [colors objectAtIndex:idx];
    return color;
}

- (id)initWithFrame:(CGRect)frame withTitle:(NSString *)t delegage:(id)d
{
    self = [super initWithFrame:frame]; 
    if (self)
    {
      NSArray *color = [self getColor];
   
//        UIColor *tcolor =     [UIColor colorWithRed:0.131 green:0.501 blue:0.351 alpha:1.000];
//        UIColor *bgcolor =   [UIColor colorWithRed:0.131 green:0.501 blue:0.351 alpha:0.200];

//        [self setBackgroundColor:bgcolor];
        
        [self setBackgroundColor:[UIColor colorWithRed:[[color objectAtIndex:0] floatValue] green:[[color objectAtIndex:1] floatValue] blue:[[color objectAtIndex:2] floatValue] alpha:0.200]];
        
        titleLbl = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 100, 30)];
//        [titleLbl setTextColor:tcolor];
        [titleLbl setTextColor:[UIColor colorWithRed:[[color objectAtIndex:0] floatValue] green:[[color objectAtIndex:1] floatValue] blue:[[color objectAtIndex:2] floatValue] alpha:1.00]];
        [titleLbl setFont:[UIFont systemFontOfSize:16.0f]];
        [titleLbl setBackgroundColor:[UIColor clearColor]];
        [titleLbl setText:t];
        [self addSubview:titleLbl];
        
        CGFloat btnheight = frame.size.height - 8;
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setFrame:CGRectMake(frame.size.width - 30, 4,30, btnheight)];
        [btn addTarget:d action:@selector(removeTag:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor:[UIColor colorWithRed:0.660 green:0.184 blue:0.239 alpha:1.000] forState:UIControlStateNormal];
        [btn setTitle:@"x" forState:UIControlStateNormal];
        [self addSubview:btn];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
